# -*- coding: utf-8 -*-
# @Time    : 2023/6/3 11:44
# @Author  : hy
# @Email   : 1596096369@qq.com
# @File    : home_page.py
# @Software: PyCharm
from pages.base_page import BasePage
from appium.webdriver.common.mobileby import MobileBy as By

class HomePage(BasePage):
    menu_locater = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_img_view"]')
    search_locater = (By.XPATH,'//*[@text="搜索菜谱"]')
    inform_locater = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_item_right_view_layout"]')
    attention_locater = [(300,200)]
    reducing_fat_locater = [(540,200)]
    store_locater = [(660,200)]
    classify_locater = [(800,200)]
    classroom_locater = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tab_widget_content_classroom"]')
    collection_locater = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tab_widget_content_collect"]')
    mine_locater = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tab_widget_content_self"]')
    text1_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/dt_visit_history"]')
    text2_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tv_dish_recommend_title"]')
    text3_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_bar_title_layout"]')
    text4_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tv_plan_recommendation"]')
    text5_locator = (By.XPATH,'//*[@text="我的订单"]')
    text6_locator = (By.XPATH,'//*[@text="厨房活动"]')
    text7_locator = (By.XPATH,'//*[@text="好吃多汁的肉包子肉馒头【步骤超详细】"]')
    goods_locator = (By.XPATH,'//*[@content-desc="德式脆皮猪肘 830g/盒 ¥99.9起 月销 11"]/android.view.View[1]')
    add_to_cart_locator = (By.XPATH,'//*[@text="加入购物车"]')
    addcart_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/webview_fragment_web_view_container"]/android.webkit.WebView[1]/android.webkit.WebView[1]/android.view.View[1]/android.view.View[1]/android.view.View[9]/android.view.View[2]/android.view.View[1]/android.view.View[6]/android.widget.Button[1]')
    addsucceed_locator = (By.XPATH,'//*[@text="已加入购物车"]')
    orders_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_bar_title_layout"]')
    shopping_cart_locator = (By.XPATH, '//*[@resource-id="com.xiachufang:id/cart_view"]')
    select_all_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/cart_all_select_check_box"]')
    settlement_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/cart_settlement_btn"]')
    quit_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_item_left_view_layout"]')
    payment_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/payment_pay_btn"]')
    sousuokuang_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/search_edit_text"]')
    sousuoanniu_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/navigation_item_right_view_layout"]')

    #点击搜索按钮
    def click_sousuo(self):
        self.find_element(self.sousuoanniu_locator).click()
    #获取付款文本
    def get_paymenttext(self):
        return self.find_element(self.payment_locator).text
    #点击退出商品页面
    def click_quit(self):
        self.find_element(self.quit_locator).click()
    #点击结算按钮
    def click_settlement(self):
        self.find_element(self.settlement_locator).click()
    #点击全选按钮
    def click_selectall(self):
        self.find_element(self.select_all_locator).click()
    #点击购物车图标
    def click_shoppingcart(self):
        self.find_element(self.shopping_cart_locator).click()
    #获取我的订单文本
    def get_orderstext(self):
        return self.find_element(self.orders_locator).text
    #进入我的订单
    def click_myorders(self):
        self.find_element(self.text5_locator).click()
    #获取添加成功弹窗文本
    def get_addsucceed(self):
        return self.find_element(self.addsucceed_locator).text
    #添加购物车
    def click_cart(self):
        self.find_element(self.addcart_locator).click()
    #添加商品至购物车
    def click_addtocart(self):
        self.find_element(self.add_to_cart_locator).click()
    #点击商品
    def click_goods(self):
        self.find_element(self.goods_locator).click()
    #获取搜索文本
    def get_text7(self):
        return self.find_element(self.text7_locator).text
    #获取分类文本
    def get_text6(self):
        return self.find_element(self.text6_locator).text
    #获取商店文本
    def get_text5(self):
        return self.find_element(self.text5_locator).text
    #获取减脂文本
    def get_text4(self):
        return self.find_element(self.text4_locator).text
    #获取通知文本
    def get_text3(self):
        return self.find_element(self.text3_locator).text
    home_page_locator = (By.XPATH,'//*[@resource-id="com.xiachufang:id/tab_widget_content_home"]/android.widget.LinearLayout[1]/android.widget.ImageView[1]')
    #获取关注文本
    def get_text2(self):
        return self.find_element(self.text2_locator).text
    #获取菜单的文本
    def get_text1(self):
        return self.find_element(self.text1_locator).text
    #点击首页左上角菜单按钮
    def click_menu(self):
        self.find_element(self.menu_locater).click()
    #点击首页的搜索框
    def click_search(self):
        self.find_element(self.search_locater).click()
    #点击首页的右上角通知按钮
    def click_inform(self):
        self.find_element(self.inform_locater).click()
    #点击首页的关注
    def click_attention(self):
        self.driver.tap(self.attention_locater,duration=500)
    # def click_attention(self,xxx):
    #     self.driver.tap(,dutation=500)
    #点击首页的减脂
    def click_reducing_fat(self):
        self.find_element(self.reducing_fat_locater).click()
    #点击首页的商店
    def click_store(self):
        self.driver.tap(self.store_locater,duration=500)
    #点击首页的分类
    def click_classify(self):
        self.driver.tap(self.classify_locater,duration=500)
    #点击下方的课堂
    def click_classroom(self):
        self.find_element(self.classroom_locater).click()
    #点击下方的收藏
    def click_collection(self):
        self.find_element(self.collection_locater).click()
    #点击下方的"我"
    def click_mine(self):
        self.find_element(self.mine_locater).click()



